<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${entityName}Mapper">

	<sql id="selectField">
	<#list dataList as var>	
		${var.columnName} as "${var.newColumn}"<#if var_has_next>,</#if>
	</#list>
	</sql>


	<!-- 新增数据 -->
	<insert id="save" parameterType="pd">
		INSERT INTO 
			${tableName}(
			<#list dataList as var>	
		    	${var.columnName}<#if var_has_next>,</#if>
		    </#list>
			)VALUES(
        	<#list dataList as var>	
		    	 ${r"#{"}${var.newColumn}${r"}"}<#if var_has_next>,</#if>
		    </#list>
        	)
	</insert>
	
	<!-- 批量新增数据 -->
	<insert id="saveBatch" parameterType="java.util.List">
		INSERT INTO 
			${tableName}(
	    	<#list dataList as var>	
		    	${var.columnName}<#if var_has_next>,</#if>
		    </#list>
			)VALUES
		<foreach collection="list" item="item" index="index" separator="," >
                (
            <#list dataList as var>	
		    	 ${r"#{item."}${var.newColumn}${r"}"}<#if var_has_next>,</#if>
		    </#list>
                )
    	</foreach >
	</insert>
	
	
	<!-- 更新数据 -->
	<update id="update" parameterType="pd">
		UPDATE 
        	${tableName}
        SET 
	 <#list dataList as var>       	
	        ${var.columnName} = ${r"#{"}${var.newColumn}${r"}"}<#if var_has_next>,</#if>
	 </#list>    	
        WHERE 
        	id = ${r"#{"}id${r"}"}
	</update>
	
	<!-- 删除数据 -->
	<delete id="delete" parameterType="pd">
		DELETE FROM 
			${tableName}
		WHERE
			id = ${r"#{"}id${r"}"}
	</delete>
	
	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		DELETE FROM 
			${tableName}
		WHERE 
			id IN
		<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
                 ${r"#{item}"}
		</foreach>
	</delete>
	
	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		SELECT 
			<include refid="selectField" />
		FROM
			${tableName}
		WHERE 
			id = ${r"#{"}id${r"}"}
	</select>
	
	<!-- 列表 -->
	<select id="dataListPage" parameterType="page" resultType="pd">
		SELECT 
			<include refid="selectField" />
		FROM 
			${tableName}
		ORDER BY
			id
		DESC
	</select>
	
	<!-- 获取所有${tableName}数据 -->
	<select id="listAll" parameterType="pd" resultType="pd">
		SELECT 
			<include refid="selectField" />
		FROM 
			${tableName}
	</select>
	
</mapper>